﻿<!DOCTYPE html>
<html>
<head>
    <title>所有栏目</title>
    <link rel="Stylesheet" type="text/css" href="${os.mcss}"/>
    <link rel="Stylesheet" type="text/css" href="/framework/assets/sys_themes/default/btn_spirites.css?version=0.5.2" />
</head>
<body>
    <div>
        <table cellpadding="0" cellspacing="0" width="100%" height="100%">
            <tr>
                <td width="250" valign="top">
                    <div style="padding:20px 20px 0 20px">
                        <input type="button" class="button" value="收起菜单" id="btn_collage" />
                    </div>
                        <div id="dg" style="padding:20px"></div>
                </td>
                <td valign="top">
                    <div class="formPanel">
                        <div id="pl" class="panel helpPanel relative autoHeight autoScroll">
                            <h2>操作帮助</h2>
                            <div class="line"></div>
                            <br/>

                            <a id="btn_apply" class="btn" href="javascript:;" style="padding:0 8px">点击生效菜单</a>

                            <div class="note">
                                微信菜单隔天生效，或重新关注可立即生效。
                            </div>
                        </div>
                    </div>
                </td>
            </tr>
        </table>
    </div>


    <script type="text/javascript" src="${os.mjs}"></script>
    <script type="text/javascript">
        var treePanel = cms.$('dg');
        function _showCategory(e, d, t) {
            if (d === "0") {
                $JS.load('pl', 'createMenu?pi=0');
            } else {
                $JS.load('pl', 'editMenu?mi='+d);
            }
        }

        //加载栏目树
       var treeObj = cms.tree.load(treePanel, ${menu}, '/framework/assets/tree/', _showCategory);
       var nodeLinks = $JS.getElementsByClassName(treePanel, 'node');
       $JS.each(nodeLinks, function(i, e) {
           if (e.nodeName == 'DIV') {
               var v =$JS.$(e,'A',{className:'node'});
               if(v.length==0)return;
               v = v[0].getAttribute('node-value');
               var html = "";
               var span  = document.createElement('SPAN');
               span.style.cssText  = 'padding-left:5px';
               span.className='hidden';
               
               var isTop = v=="0";
               if(v.indexOf("-")==-1){
                   html +='<img src="/framework/assets/icons/admin/add.gif" title="创建子菜单" style="border:none"  onclick="return tree_add(event,\''+ v +'\')"/>';
                   if(!isTop){
                       html += " |";
                   }
               }
               
               if(!isTop) {
                   html +='<img src="/framework/assets/icons/admin/delete.gif" title="删除菜单" style="border:none" onclick="return tree_del(event,\''+ v +'\')"/>';
               }

               span.innerHTML = html;
               e.appendChild(span);

               $JS.hover(e,
                   (function(e){
                       return function(){
                           e.className='';
                       };
                   })(span),
                   (function(e){
                       return function(){
                           e.className='hidden';
                       };
                   })(span)
                   );
           }
       });

       function tree_add(e,pi){
           $JS.load('pl', 'createMenu?pi='+pi);
           return false;
       }

        function tree_del(e, id) {
            if (confirm('删除后不可恢复，您确定要继续吗？')) {
                $JS.xhr.jsonPost('DelMenu', { mi: id }, function(json) {
                    if (json.result) {
                        parent.M.alert(json.message);
                        location.reload();
                    }
                });
            }
        }

      

        cms.$('btn_collage').onclick = function () {
            if (this.value.indexOf('收起') != -1) {
                treeObj.closeAll();
                this.value = '展开菜单';
            } else {
                treeObj.openAll();
                this.value = '收起菜单';
            }
        };
        
        cms.$('btn_apply').onclick = function() {
            $JS.xhr.jsonPost('ApplyMenu', {}, function(json) {
                parent.M.alert(json.message);
            });
        }

    </script>

</body>
</html>
